#include "stdafx.h"

CStringW UTF8_To_UCS2(LPCSTR utf8_str)
{
	ASSERT(utf8_str);

	int ucs2_len = MultiByteToWideChar(CP_UTF8, 0, utf8_str, -1, NULL, 0);
	if (ucs2_len == 0)
		return CStringW();

	WCHAR* ucs2_str = new WCHAR[ucs2_len];
	ucs2_len = MultiByteToWideChar(CP_UTF8, 0, utf8_str, -1, ucs2_str, ucs2_len);

	CStringW strUCS2 = ucs2_str;
	delete []ucs2_str;

	return strUCS2;
}


CStringA UCS2_To_UTF8(LPCWSTR ucs2_str)
{
	ASSERT(ucs2_str);

	int utf8_len = WideCharToMultiByte(CP_UTF8, 0, ucs2_str, -1, NULL, 0, NULL, NULL);
	if (utf8_len == 0)
		return CStringA();

	CHAR* utf8_str = new CHAR[utf8_len];
	WideCharToMultiByte(CP_UTF8, 0, ucs2_str, -1, utf8_str, utf8_len, NULL, NULL);

	CStringA strUTF8 = utf8_str;
	delete []utf8_str;

	return strUTF8;
}
